package cn.ffcs.uec.common.vo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import lombok.Getter;
import lombok.Setter;
import cn.ffcs.uec.common.component.BdPsnclTreeBandboxExt;
import cn.ffcs.uec.organization.vo.OrganizationRelationVo;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.zkplus.zul.tree.node.TreeNodeEntity;

/**
 * 人员类别--字典表
 * 
 * @Title:
 * @Description:
 * @author Wang Yiren
 * @版权 FFCS（C） 2017
 * @date 2018年6月28日
 */
public class UecBdPsncl implements Serializable, TreeNodeEntity {

    private static final long serialVersionUID = -6544624653554582836L;

    private BdPsnclTreeBandboxExt component;// 所在组件

    private boolean end;// 是否末端节点

    @Getter
    @Setter
    private Long bdPsnclId;

    @Getter
    @Setter
    private Long monthId;

    @Getter
    @Setter
    private String code;

    @Getter
    @Setter
    private String creationTime;

    @Getter
    @Setter
    private String creator;

    @Getter
    @Setter
    private String enableState;

    @Getter
    @Setter
    private String modifiedTime;

    @Getter
    @Setter
    private String modifier;

    @Getter
    @Setter
    private String name;

    @Getter
    @Setter
    private String parentId; //父节点

    @Getter
    @Setter
    private String pkOrg;

    @Getter
    @Setter
    private String pkPsncl;

    @Getter
    @Setter
    private String ts;

    @Getter
    @Setter
    private String dr;

    public BdPsnclTreeBandboxExt getComponent() {
        return component;
    }

    public void setComponent(BdPsnclTreeBandboxExt component) {
        this.component = component;
    }

    public boolean isEnd() {
        return end;
    }

    public void setEnd(boolean end) {
        this.end = end;
    }

    public static UecBdPsncl newInstance() {
        return new UecBdPsncl();
    }

    /**
     * 根节点id
     */
    @Getter
    @Setter
    private String rootId = "~";

    /**
     * 是否是根节点
     */
    @Getter
    @Setter
    private Boolean isRoot = false;// 设置为true则表示用来获取根节点

    @Override
    public boolean isGetRoot() {
        return this.isRoot;
    }

    @SuppressWarnings("unchecked")
    @Override
    public ArrayList<TreeNodeEntity> getRoot() {
        String sqlStr = "SELECT * FROM UEC_BD_PSNCL WHERE PARENT_ID = ? ";
        List<Object> params = new ArrayList<Object>();
        params.add(this.rootId);
        List<UecBdPsncl> list = OrganizationRelationVo.repository().jdbcFindList(sqlStr, params,
                UecBdPsncl.class);
        Object object = list;
        return (ArrayList<TreeNodeEntity>) object;
    }

    @SuppressWarnings("unchecked")
    @Override
    public ArrayList<TreeNodeEntity> getChildren() {
        if (!StrUtil.isNullOrEmpty(this.pkPsncl)) {
            String sqlStr = "SELECT * FROM UEC_BD_PSNCL WHERE PARENT_ID = ? ";
            List<Object> params = new ArrayList<Object>();
            params.add(this.pkPsncl);
            List<UecBdPsncl> list = OrganizationRelationVo.repository().jdbcFindList(sqlStr, params,
                    UecBdPsncl.class);
            Object object = list;
            return (ArrayList<TreeNodeEntity>) object;
        }
        return null;
    }

    @Override
    public String getLabel() {
        if (!StrUtil.isNullOrEmpty(this.name)) {
            return this.name;
        } else {
            return "";
        }
    }
}
